<?php
/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition End User License Agreement
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magento.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     default_default
 * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license http://www.magento.com/license/enterprise-edition
 */
?>

<?php
$_htmlId = $this->getHtmlId() ? $this->getHtmlId() : '_' . uniqid();
?>
<button style="" onclick="" class="scalable" type="button" id="generateBtn<?php echo $_htmlId ?>">
    <span><span><span><?php echo Mage::helper('enterprise_giftcardaccount')->__('Generate'); ?></span></span></span>
</button>
<br />
<p class="nm"><small>
<?php
$_usage = $this->getUsage();
echo Mage::helper('enterprise_giftcardaccount')->__('Code Pool used: <b>%.2f%%</b> (free <b>%d</b> of <b>%d</b> total).', $_usage->getPercent(), $_usage->getFree(), $_usage->getTotal());
?>
</small></p>
<br />

<script type="text/javascript">
//<![CDATA[
function redirectToGeneration()
{
    var url = '<?php echo Mage::getSingleton('adminhtml/url')->getUrl('*/giftcardaccount/generate'); ?>';
    if (confirm('<?php echo Mage::helper('core')->jsQuoteEscape(Mage::helper('enterprise_giftcardaccount')->__('Do you really want to proceed? All unsaved changes will be lost.')); ?>')) {
        if (Prototype.Browser.IE) {
            var generateLink = new Element('a', {href: url});
            $$('body')[0].insert(generateLink);
            generateLink.click();
        } else {
            window.location.href = url;
        }
    }
}

function disableGenerateButton()
{
    var elem = $('generateBtn<?php echo $_htmlId ?>');
    elem.disabled = true;
    elem.addClassName('disabled');
}

Event.observe('generateBtn<?php echo $_htmlId ?>', 'click', redirectToGeneration)

$('giftcard_giftcardaccount_general').select('input', 'select').each(function(elem) {
    Event.observe($(elem.id), 'change', disableGenerateButton);
});
//]]>
</script>
